package com.qidian.hw.service.impl;

import com.qidian.hw.dao.SolutionDAO;
import com.qidian.hw.dao.impl.SolutionDAOImpl;
import com.qidian.hw.pojo.Solution;
import com.qidian.hw.service.SolutionService;
import com.qidian.hw.tools.dto.Pager;

import java.util.ArrayList;

/**
 * @Author ꒰ঌ(李ᆺ琛)໒꒱
 * @Date 2022/8/19 20:05
 * @Version 1.8
 */
public class SolutionServiceImpl implements SolutionService {
    private SolutionDAO solutionDAO = new SolutionDAOImpl ();

    @Override
    public int saveSolution(Solution solution) {
        return solutionDAO.saveSolution (solution);
    }

    @Override
    public int deleteSolution(long solutionId) {
        return solutionDAO.deleteSolution (solutionId);
    }

    @Override
    public int updateSolution(Solution solution) {
        return solutionDAO.updateSolution (solution);
    }

    @Override
    public ArrayList<Solution> listSolution() {
        return solutionDAO.listSolution ();
    }

    @Override
    public Solution querySolutionById(long solutionId) {
        return solutionDAO.querySolutionById (solutionId);
    }

    @Override
    public Pager queryByPage(int page, int size, String title, int catId) {
        Pager pager = new Pager ();
        pager.setPage (page);
        pager.setSize (size);
        // 查询总条数
        int total = solutionDAO.count (title, catId);
        pager.setTotal (total);
        // 计算最大页码
        int maxPage = (int) Math.ceil (total * 1.0 / size);
        pager.setMaxPage (maxPage);
        // 查询数据列表
        ArrayList rows = solutionDAO.queryByPage (page, size, title, catId);
        pager.setRows (rows);
        return pager;
    }
    @Override
    public int deleteBatch(String[] ids) {
        return solutionDAO.deleteBatch (ids);
    }
}
